package androidx.fragment.app;

import android.os.Parcelable;
import android.view.View;
import android.view.ViewGroup;
import androidx.lifecycle.e;
import androidx.viewpager.widget.a;

public abstract class q extends a {

    /* renamed from: b  reason: collision with root package name */
    private final m f651b;

    /* renamed from: c  reason: collision with root package name */
    private final int f652c;

    /* renamed from: d  reason: collision with root package name */
    private u f653d;
    private Fragment e;
    private boolean f;

    @Deprecated
    public q(m mVar) {
        this(mVar, 0);
    }

    public q(m mVar, int i) {
        this.f653d = null;
        this.e = null;
        this.f651b = mVar;
        this.f652c = i;
    }

    private static String r(int i, long j) {
        return "android:switcher:" + i + ":" + j;
    }

    public void a(ViewGroup viewGroup, int i, Object obj) {
        Fragment fragment = (Fragment) obj;
        if (this.f653d == null) {
            this.f653d = this.f651b.i();
        }
        this.f653d.l(fragment);
        if (fragment.equals(this.e)) {
            this.e = null;
        }
    }

    /* JADX INFO: finally extract failed */
    public void b(ViewGroup viewGroup) {
        u uVar = this.f653d;
        if (uVar != null) {
            if (!this.f) {
                try {
                    this.f = true;
                    uVar.k();
                    this.f = false;
                } catch (Throwable th) {
                    this.f = false;
                    throw th;
                }
            }
            this.f653d = null;
        }
    }

    public Object g(ViewGroup viewGroup, int i) {
        if (this.f653d == null) {
            this.f653d = this.f651b.i();
        }
        long q = q(i);
        Fragment X = this.f651b.X(r(viewGroup.getId(), q));
        if (X != null) {
            this.f653d.g(X);
        } else {
            X = p(i);
            this.f653d.b(viewGroup.getId(), X, r(viewGroup.getId(), q));
        }
        if (X != this.e) {
            X.setMenuVisibility(false);
            if (this.f652c == 1) {
                this.f653d.r(X, e.b.STARTED);
            } else {
                X.setUserVisibleHint(false);
            }
        }
        return X;
    }

    public boolean h(View view, Object obj) {
        return ((Fragment) obj).getView() == view;
    }

    public void j(Parcelable parcelable, ClassLoader classLoader) {
    }

    public Parcelable k() {
        return null;
    }

    public void l(ViewGroup viewGroup, int i, Object obj) {
        Fragment fragment = (Fragment) obj;
        Fragment fragment2 = this.e;
        if (fragment != fragment2) {
            if (fragment2 != null) {
                fragment2.setMenuVisibility(false);
                if (this.f652c == 1) {
                    if (this.f653d == null) {
                        this.f653d = this.f651b.i();
                    }
                    this.f653d.r(this.e, e.b.STARTED);
                } else {
                    this.e.setUserVisibleHint(false);
                }
            }
            fragment.setMenuVisibility(true);
            if (this.f652c == 1) {
                if (this.f653d == null) {
                    this.f653d = this.f651b.i();
                }
                this.f653d.r(fragment, e.b.RESUMED);
            } else {
                fragment.setUserVisibleHint(true);
            }
            this.e = fragment;
        }
    }

    public void n(ViewGroup viewGroup) {
        if (viewGroup.getId() == -1) {
            throw new IllegalStateException("ViewPager with adapter " + this + " requires a view id");
        }
    }

    public abstract Fragment p(int i);

    public long q(int i) {
        return (long) i;
    }
}
